package com.area.cth.mapper;

import com.area.cth.pojo.Exchange;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExchangeMapper {
    @Insert("insert into exchange(create_user,goods_category,goods_description,is_free,intention_category," +
            "img1,img2,img3,img4,img5,img6,img7,img8,img9,address,audit_state,create_time,update_time) " +
            "values (#{createUser},#{goodsCategory},#{goodsDescription},#{isFree},#{intentionCategory}," +
            "#{img1},#{img2},#{img3},#{img4},#{img5},#{img6},#{img7},#{img8},#{img9}," +
            "#{address},#{auditState},#{createTime},#{updateTime})")
    void addExchange(Exchange e);

    List<Exchange> getExchangeListByIsFree(Integer f);

    @Select("select * from exchange where create_user = #{id} and audit_state=#{s}")
    List<Exchange> getMyExchangeListByAudit(Integer id, String s);

    List<Exchange> getExchangeTrueByUserList(Integer userId, String s);

    Exchange getExchangeById(Integer id);

    @Update("update exchange set goods_category=#{goodsCategory},intention_category=#{intentionCategory}," +
            "goods_description=#{goodsDescription},address=#{address},audit_state=#{auditState}," +
            "update_time=now() where id=#{id}")
    void update(Exchange e);

    @Delete("delete from exchange where id=#{id}")
    void delete(Integer id);

    @Update("update exchange set audit_state=#{audit}," +
            "update_time=now() where id=#{id}")
    void updateAudit(String audit, Integer id);

    IPage<Exchange> exchangeList(Page<Exchange> page, String auditState, Integer isFree, String keyword);
}
